<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/27 0027
 * Time: 16:42
 */

namespace app\api\controller\v1;

use app\api\model\Theme as ThemeModel;
use app\common\lib\exception\ApiException;
use app\api\model\Product as ProductModel;



class Product
{
    public function getRecent($count = 15)
    {
        $result = ProductModel::getMostRecent($count);
        if ($result) {
            $collection = collection($result);
            $result = $collection->hidden(['summary']);
            return show(200, '', $result);
        } else {
            throw new ApiException('数据不存在', '500', '401');
        }
    }

    public function getAllInCategory($id)
    {
        $result = ProductModel::getProductByCategoryID($id);
        if ($result) {
            $collection = collection($result);
            $result = $collection->hidden(['summary']);
            return show(200, '', $result);
        } else {
            throw new ApiException('数据不存在', '500', '401');
        }
    }


}